package com.example.liyuehui.paging.viewmodel;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.LiveData;
import android.arch.paging.LivePagedListBuilder;
import android.arch.paging.PagedList;
import android.support.annotation.NonNull;

import com.example.liyuehui.paging.datasource.TextDataSourceFactory;

public class TextViewModel extends AndroidViewModel {
	private LiveData<PagedList<String>> pagedListLiveData;
	private LiveData<TextDataSourceFactory.NetStatus> netStatusLiveData;

	public TextViewModel(@NonNull Application application) {
		super(application);
	}

	public LiveData<PagedList<String>> getPagedListLiveData() {
		if (pagedListLiveData == null) {
			TextDataSourceFactory factory = new TextDataSourceFactory();
			netStatusLiveData = factory.netStatusLiveData;
			pagedListLiveData = new LivePagedListBuilder(factory,
					new PagedList.Config.Builder().setInitialLoadSizeHint(15).
							setPageSize(15).setPrefetchDistance(5).
							setEnablePlaceholders(true).
							build()).build();
		}
		return pagedListLiveData;
	}

	public LiveData<TextDataSourceFactory.NetStatus> getNetStatusLiveData() {
		return netStatusLiveData;
	}
}
